package com.example.androidproject.ui.fragment;

import android.app.Activity;
import android.os.Handler;
import android.view.View;
import android.widget.Button;

import com.example.androidproject.R;
import com.example.androidproject.ui.base.IBaseFragment;
import com.example.androidproject.ui.presenter.TestPresenter;
import com.example.androidproject.view.TestView;
import com.hyg.base.ui.common.FragmentContainerActivity;
import com.hyg.common.utils.LogUtils;

import butterknife.BindView;

/**
 * FileName: TestMvpFragment
 * Author: huangyuguang
 * Date: 2022/5/11
 * Description: mvp
 */
public class TestMvpFragment extends IBaseFragment<TestPresenter> implements TestView {
    @BindView(R.id.btn)
    Button button;

    public static void launch(Activity from){
        FragmentContainerActivity.getInstance().launch(from, TestMvpFragment.class);
    }

    @Override
    public String initTitle() {
        return "试试看MVP";
    }

    @Override
    protected TestPresenter createPresenter() {
        return new TestPresenter(this);
    }

    @Override
    protected int provideContentViewId() {
        return R.layout.activity_main;
    }

    @Override
    protected void initViewAndData() {
//        mPresenter.getTestData();
        button.setText("go to MVC");
        findViewById(R.id.btn).setOnClickListener(v -> TestMvcFragment.launch(getActivity()));

        button.setVisibility(View.GONE);
        mStateView.showRetry();
        mStateView.setOnRetryClickListener(() -> new Handler().postDelayed(() -> {
            mStateView.showContent();
            button.setVisibility(View.VISIBLE);
        },2000));
    }

    @Override
    public void onGetTestDataSuccess(String str) {

    }

    @Override
    public void onError(String error) {

    }

    @Override
    public void onResume() {
        super.onResume();
        LogUtils.d("OkHttp","onResume ---");
    }

    @Override
    public void onStop() {
        super.onStop();
        LogUtils.d("OkHttp","onStop ---");
    }
}
